﻿#region Copyright (c) 2000-2008 Developer Express Inc.
/*
{*******************************************************************}
{                                                                   }
{       Developer Express .NET Component Library                    }
{       AgDataGrid                                 }
{                                                                   }
{       Copyright (c) 2000-2008 Developer Express Inc.              }
{       ALL RIGHTS RESERVED                                         }
{                                                                   }
{   The entire contents of this file is protected by U.S. and       }
{   International Copyright Laws. Unauthorized reproduction,        }
{   reverse-engineering, and distribution of all or any portion of  }
{   the code contained in this file is strictly prohibited and may  }
{   result in severe civil and criminal penalties and will be       }
{   prosecuted to the maximum extent possible under the law.        }
{                                                                   }
{   RESTRICTIONS                                                    }
{                                                                   }
{   THIS SOURCE CODE AND ALL RESULTING INTERMEDIATE FILES           }
{   ARE CONFIDENTIAL AND PROPRIETARY TRADE                          }
{   SECRETS OF DEVELOPER EXPRESS INC. THE REGISTERED DEVELOPER IS   }
{   LICENSED TO DISTRIBUTE THE PRODUCT AND ALL ACCOMPANYING .NET    }
{   CONTROLS AS PART OF AN EXECUTABLE PROGRAM ONLY.                 }
{                                                                   }
{   THE SOURCE CODE CONTAINED WITHIN THIS FILE AND ALL RELATED      }
{   FILES OR ANY PORTION OF ITS CONTENTS SHALL AT NO TIME BE        }
{   COPIED, TRANSFERRED, SOLD, DISTRIBUTED, OR OTHERWISE MADE       }
{   AVAILABLE TO OTHER INDIVIDUALS WITHOUT EXPRESS WRITTEN CONSENT  }
{   AND PERMISSION FROM DEVELOPER EXPRESS INC.                      }
{                                                                   }
{   CONSULT THE END USER LICENSE AGREEMENT FOR INFORMATION ON       }
{   ADDITIONAL RESTRICTIONS.                                        }
{                                                                   }
{*******************************************************************}
*/
#endregion Copyright (c) 2000-2008 Developer Express Inc.

using System.Collections.ObjectModel;
using System.Windows.Controls;
using System.Windows;
namespace DevExpress.AgDataGrid.Internal {
	public abstract class PanelColumnElementsBuilderBase {
		Panel panel;
		ReadOnlyCollection<AgDataGridColumn> visibleColumns;
		public PanelColumnElementsBuilderBase(ReadOnlyCollection<AgDataGridColumn> visibleColumns, Panel panel) { 
			this.visibleColumns = visibleColumns;
			this.panel = panel;
		}
		public Panel Panel { get { return panel; } }
		public ReadOnlyCollection<AgDataGridColumn> VisibleColumns { get { return visibleColumns; } }
		public void BuildElements() {
			if(Panel == null) return;
			Panel.Children.Clear();
			foreach(AgDataGridColumn column in VisibleColumns) {
				InsertElement(column);
			}
		}
		protected virtual void InsertElement(AgDataGridColumn column) {
			Panel.Children.Add(GetElement(column));
		}		
		protected abstract FrameworkElement GetElement(AgDataGridColumn column);
	}
	public class PanelColumnHeadersBuilder : PanelColumnElementsBuilderBase {
		public PanelColumnHeadersBuilder(ReadOnlyCollection<AgDataGridColumn> visibleColumns, Panel panel)
			: base(visibleColumns, panel) { }
		protected override FrameworkElement GetElement(AgDataGridColumn column) {
			return column.HeaderControl;
		}
	}
	public class PanelTotalBuilder : PanelColumnElementsBuilderBase {
		public PanelTotalBuilder(ReadOnlyCollection<AgDataGridColumn> visibleColumns, Panel panel)
			: base(visibleColumns, panel) { }
		protected override FrameworkElement GetElement(AgDataGridColumn column) {
			return column.TotalCellControl;
		}
	}
	public class PanelGroupColumnHeadersBuilder : PanelColumnElementsBuilderBase {
		public PanelGroupColumnHeadersBuilder(ReadOnlyCollection<AgDataGridColumn> visibleColumns, Panel panel)
			: base(visibleColumns, panel) {
		}
		protected override FrameworkElement GetElement(AgDataGridColumn column) {
			return column.GroupedHeaderControl;
		}
		public void BuildElements(UIElement emptyElement) {
			if(Panel == null) return;
			base.BuildElements();
			if(Panel.Children.Count == 0 && emptyElement != null)
				Panel.Children.Add(emptyElement);
		}
	}
	public class PanelColumnCellsBuilder : PanelColumnElementsBuilderBase {
		AgDataGridRow row;
		public PanelColumnCellsBuilder(AgDataGridRow row, ReadOnlyCollection<AgDataGridColumn> visibleColumns, Panel panel)
			: base(visibleColumns, panel) {
			this.row = row;
		}
		protected AgDataGridRow Row { get { return row; } }
		protected override FrameworkElement GetElement(AgDataGridColumn column) {
			return Row.GetCellControl(column);
		}
	}
}
